MODULE CONFIG
!-----------------------------------------------------------------------
! Wesentliche Programmkonfigurationen:
!-----------------------------------------------------------------------
!
!     rkind     : selected real kind / singl-double-quadrouble precision
!
!     np        : Anzahl der Gitterpunkte
!
!     BCflag    : BCflag ist in den Pseudozellen 1; sonst 0
!                     BCflag(1:2)       = z1
!                     BCflag(3:np-3)    = z0
!                     BCflag(np-2:np)   = z1
!
!-----------------------------------------------------------------------

      implicit none

      private
      public :: rkind, np, BCflag


      integer, parameter  :: rkind = 8  ! moeglich: 4, 8, 16 (single, double, quadrouple) !ppp

      integer, parameter  :: np = 500         !Anzahl der Gitterpunkte  !ppp

      real(kind=rkind), parameter, dimension(np) :: &
           BCflag = (/ 1._rkind, 1._rkind, &
                                           0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 50
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 100
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 150
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 200
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 250
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 300
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 350
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 400
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &! 450
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind,   &
                       0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, 0._rkind, &
                                                                                             1._rkind, 1._rkind, 1._rkind /)  ! 500

END MODULE CONFIG





MODULE PRIMVAR
!-----------------------------------------------------------------------
! primaere Variable, Jacobimatrix etc.
!-----------------------------------------------------------------------
!
!     ng         : Anzahl der Gleichungen
!     nv         : Anzahl der Variablen
!
!     DG         : Jacobimatrix DG(ng,nv,x,np), x.. Anzahl der Nebendiagonalen, z.b.: -2,-1,0,1,2
!     DX         : Loesungvektor des Gleichungssystems DX(ng,np)
!     G          : rechte Seite des Gleichungssystems G(ng,np)
!     Gnorm      : Normierungsfaktoren fuer das Gleichungssystem
!     Xnorm      : Normierungsfaktoren fuer den Variablensatz
!     X          : primaere SHD-Variablen zum neuen Zeitpunkt (unbekannt)
!     XA         : primaere SHD-Variablen zum alten Zeitpunkt (sind bekannt)
!     XZ         : primaere SHD-Variablen zeitlich zentriert - zwischen X und XA
!     X_extrapol : primaere SHD-Variablen -- ganz alt -- NUR ZUM EXTRAPOLIEREN
!     DG_???     : Indizes zum Auswaehlen der Diagonale in der Jacobimatrix
!
!     Beispiele fuer die Indizierung:
!
!               DG(MD,MR,im1,i) =  ...
!                  MD ................... Ableitung der Kontinuitaetsgleichung
!                     MR ................ nach dem Radius
!                        im1 ............ an der relative Position im1
!                            i .......... Ableitung betrifft Gleichung des Gitterpunktes i
!
!                X(MD,i) =  ...
!                  MD ................... Dichte
!                     i ................. am Gitterpunkt i
!
!
!   +-------+--------+----------------------------------------+--------------+-------------------+
!   | Num.  | Marker | Gleichung                              |  Variable    | File(s)           |
!   +-------+--------+----------------------------------------+--------------+-------------------+
!   |   1.  |  MR    | Gittergleichung                        |  R           | G_grid.f90        |
!   |   2.  |  MD    | Kontinuitaetsgleichung (Saeulendichte) |  rho_col     | G_cont.f90        |
!   |   3.  |  ME    | Energiegleichung                       |  e           | G_ene.f90         |
!   |   4.  |  MUr   | Bewegungsgleichung radial              |  u_r         | G_mot_r.f90       |
!   |   5.  |  MUp   | Bewegungsgleichung in phi Richtung     |  u_phi       | G_mot_phi.f90     |
!   |   6.  |  MJ    | Strahlungsenergiedichte (fuer z=0)     |  J_0         | G_radene.f90      |
!   |   7.  |  MH    | Strahlungsfluss (fuer z=0)             |  H_0         | G_radflx.f90      |
!   +-------+--------+----------------------------------------+--------------+-------------------+
!
!
!-----------------------------------------------------------------------

      use config, only : rkind, np

      implicit none

      private
      public :: nv, ng, DG, DG_im2, DG_im1, DG_i, DG_ip1, DG_ip2, G, Gnorm, DX, &
                X, XZ, XA, X_extrapol, Xnorm, MR, MD, ME, MUr, MUp, MJ, MH


      integer, parameter  :: nv = 7           !Anzahl der Variablen   !ppp
      integer, parameter  :: ng = 6           !Anzahl der Gleichungen !ppp

      integer, parameter  :: MR=7, MD=2, ME=3, MUr=4, MUp=5, MJ=6, MH=1 !ppp

      ! Das Hauptdiagonalelement von DG hat den Index 0
      ! Der 2te Index von DG geht bis nv da ich so immer die selben DG_xxx.f90 subroutines verwenden kann, auch wenn ich nicht alle Varibalen mitloese.
      ! Nicht mitgeloeste Variablen sind notgedrungen Konstanten, daher kann ich die Ableitungen nach diese Variablen einfach ignorieren.
      real(kind=rkind)    :: DG(ng,nv,-2:+2,np)
      integer, parameter  :: DG_im2=-2, DG_im1=-1, DG_i=0, DG_ip1=1, DG_ip2=2

      ! Die Variablen folgender Zeile sind mit dem Loesen assoziiert - deswegen Dimension ng
      real(kind=rkind)    :: G(ng,np), Gnorm(ng,np), DX(ng,np)

      ! Der eigentliche Variablensatz kann groesser als die Anzahl der Gleichungen sein.
      ! Xnorm habe ich der der Einfachheit halber mitgezogen da ich auf diese Weise calc_Xnorm
      ! unveraendert lassen kann, unabhaengig davon wieviele Gleichungen ich tatsaechlich loese.
      real(kind=rkind)    :: X(nv,np), XZ(nv,np), XA(nv,np), X_extrapol(nv,np), Xnorm(nv,np)

END MODULE PRIMVAR





MODULE RBVAR
!-----------------------------------------------------------------------
! Randbedingungen
!-----------------------------------------------------------------------
!
!     M_star   : Masse des zentralen Sterns
!     L_star   : Leuchtkraft des zentralen Sterns
!     H_star   : Effektiver Abstand des zentralen Sterns von der Mittelebene der Scheibe, z.B. H_star = 4/(3pi) * R_star
!     f_irr    : Effizienz der Einstrahlung, f_irr = (1-albedo) * H_phot/H_p
!     R_in     : Radius des Innenrandes
!     rho0_in  : Zentraldichte am Innenrand
!     rho_in   : Saeulendichte am Innenrand
!     e_in     : innere Energie am Innenrand
!     R_out    : Radius des Aussenrandes
!     rho0_out : Zentraldichte am Aussenrand
!     rho_out  : Saeulendichte am Aussenrand
!     e_out    : innere Energie am Aussenrand
!

      use config, only : rkind

      implicit none

      private
      public :: M_star, L_star, H_star, f_irr, R_in, rho0_in, rho_in, e_in, R_out, rho0_out, rho_out, e_out


      real(kind=rkind) :: M_star, L_star, H_star, f_irr
      real(kind=rkind) :: R_in, rho0_in, rho_in, e_in, R_out, rho0_out, rho_out, e_out

END MODULE RBVAR
